home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Updates / PowerPC / pdflib / bind / python / pdfclock.py < prev    next >
Text File  |  2000-05-16  |  2KB  |  93 lines

  1. #!/usr/bin/python
  2. # PDFlib client: pdfclock example in Python
  3. # (C) Thomas Merz 1998-99
  4.  
  5. from sys import *
  6. from time import *
  7. from pdflib import *
  8.  
  9. RADIUS = 200.0;
  10. MARGIN = 20.0;
  11.  
  12. p = PDF_new()
  13.  
  14. if PDF_open_file(p, "pdfclock_py.pdf") == -1:
  15.     print 'Couldn\'t open PDF file!', "pdfclock_py.pdf"
  16.     exit(2);
  17.  
  18. PDF_set_info(p, "Author", "Thomas Merz")
  19. PDF_set_info(p, "Creator", "pdfclock.py")
  20. PDF_set_info(p, "Title", "PDF clock (Python)")
  21.  
  22. PDF_begin_page(p, 2 * (RADIUS + MARGIN), 2 * (RADIUS + MARGIN));
  23.  
  24. PDF_set_transition(p, "wipe");
  25. PDF_set_duration(p, 0.5);
  26.  
  27. PDF_translate(p, RADIUS + MARGIN, RADIUS + MARGIN);
  28. PDF_setrgbcolor(p, 0.0, 0.0, 1.0);
  29. PDF_save(p);
  30.  
  31. # minute strokes 
  32. PDF_setlinewidth(p, 2.0);
  33. for alpha in range(0, 360, 6):
  34.     PDF_rotate(p, 6.0);
  35.     PDF_moveto(p, RADIUS, 0.0);
  36.     PDF_lineto(p, RADIUS-MARGIN/3, 0.0);
  37.     PDF_stroke(p);
  38.  
  39. PDF_restore(p);
  40. PDF_save(p);
  41.  
  42. # 5 minute strokes
  43. PDF_setlinewidth(p, 3.0);
  44. for alpha in range(0, 360, 30):
  45.     PDF_rotate(p, 30.0);
  46.     PDF_moveto(p, RADIUS, 0.0);
  47.     PDF_lineto(p, RADIUS-MARGIN, 0.0);
  48.     PDF_stroke(p);
  49.  
  50. (tm_year, tm_year, tm_day,
  51. tm_hour, tm_min, tm_sec, 
  52. tm_weekday, tm_julian, tm_ds) = localtime(time());
  53.  
  54. # draw hour hand 
  55. PDF_save(p);
  56. PDF_rotate(p, (-((tm_min/60.0) + tm_hour - 3.0) * 30.0));
  57. PDF_moveto(p, -RADIUS/10, -RADIUS/20);
  58. PDF_lineto(p, RADIUS/2, 0.0);
  59. PDF_lineto(p, -RADIUS/10, RADIUS/20);
  60. PDF_closepath(p);
  61. PDF_fill(p);
  62. PDF_restore(p);
  63.  
  64. # draw minute hand
  65. PDF_save(p);
  66. PDF_rotate(p, (-((tm_sec/60.0) + tm_min - 15.0) * 6.0));
  67. PDF_moveto(p, -RADIUS/10, -RADIUS/20);
  68. PDF_lineto(p, RADIUS * 0.8, 0.0);
  69. PDF_lineto(p, -RADIUS/10, RADIUS/20);
  70. PDF_closepath(p);
  71. PDF_fill(p);
  72. PDF_restore(p);
  73.  
  74. # draw second hand
  75. PDF_setrgbcolor(p, 1.0, 0.0, 0.0);
  76. PDF_setlinewidth(p, 2);
  77. PDF_save(p);
  78. PDF_rotate(p, -((tm_sec - 15.0) * 6.0));
  79. PDF_moveto(p, -RADIUS/5, 0.0);
  80. PDF_lineto(p, RADIUS, 0.0);
  81. PDF_stroke(p);
  82. PDF_restore(p);
  83.  
  84. # draw little circle at center
  85. PDF_circle(p, 0, 0, RADIUS/30);
  86. PDF_fill(p);
  87.  
  88. PDF_restore(p);
  89. PDF_end_page(p);
  90.  
  91. PDF_close(p);
  92. PDF_delete(p);
  93.